package henu.util;

import henu.DB.DB;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

public class User {
	 private int userID;
	    private String userName;
	    private Date startTime;
	    
	    public User(){}
	    
	    public User(int id){
	        this.userID =id ;
	        if(!FromDb())
	            this.userID=-1;
	    }
	    private boolean FromDb() {
	        int row = -1;
	        String sql ="select * from user where user_id="+this.userID;
	        ResultSet rs = DB.RunSelect(sql);
	        try{
	            rs.last();
	            row = rs.getRow();
	            if(row == 1){
	                this.userID = rs.getInt("USER_ID");
	                this.userName = rs.getString("USER_NAME");
	                this.startTime = rs.getDate("START_TIME");
	                return true;
	            }else
	                return false;
	        }catch(SQLException e){
	            e.printStackTrace();
	            return false;
	        }finally{
	            DB.close();
	        }
	    }
		public int getUserID() {
			return userID;
		}
		public void setUserID(int userID) {
			this.userID = userID;
		}
		public String getUserName() {
			return userName;
		}
		public void setUserName(String userName) {
			this.userName = userName;
		}
		public Date getStartTime() {
			return startTime;
		}
		public void setStartTime(Date startTime) {
			this.startTime = startTime;
		}
}
